<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<%-- <%@include file="edit.jsp"%> --%>
<html>
<head>
<script type="text/javascript">
	$(function() {
		$('#isOpen').radiobox({name:'entity.markPublish',value:'1',data:[['1','公开'],['3','私密']]});
		$('#enabled').radiobox({name:'entity.enabled',value:true,data:[[true,'有效'],[false,'无效']]});
		$('#iUserType').combobox({
		    data:$codelist('userType'),editable:false,width:180
		});
		$('#toolbar').toolbar({buttons:[
			{name:'save',iconCls:'icon-save',text:'发送'}
	  	],handler:handler});
		
		//加载通讯录
		$('#grid').datagrid({
		    url:'/admin/user/page',pagination:true,singleSelect:true,rownumbers:true,striped:true,fitColumns:true,fit:true,
		    columns:[[
		    	{field:'ck',checkbox:true},
		    	{field:'nickname',title:'姓名'},
				{field:'username',title:'用户名'},
				{field:'type',title:'用户类型',formatter:function(v,r,i){
					return $codetext('userType',v)
				}},
				{field:'enabled',title:'启用标记',formatter:$g.bv},
		    ]]
			,onClickRow:function(i,r) {
				$('#toolbar').toolbar('enableAll');
			}
			,onSelect:function(i,r){
				appendRow(r);
			}
		});
		
		//加载通讯录
		$('#select_grid').datagrid({
		    singleSelect:true,rownumbers:true,striped:true,fitColumns:true,fit:true,
		    columns:[[
		    	{field:'nickname',title:'姓名'},
				{field:'username',title:'用户名'},
				{field:'type',title:'用户类型',formatter:function(v,r,i){
					return $codetext('userType',v)
				}},
				{field:'-',title:'操作',formatter:function(v,r,i){
					return '<a href="#" onclick="removeRow('+i+');">移除</a>';
				}}
		    ]]
		});
		
		function appendRow(r) {
			var rows = $('#select_grid').datagrid("getRows");
			var add = true;
			for(var i=0;i<rows.length;i++){
				if(r.id==rows[i].id){
					add = false;
					break;  
				}
			}
			if(add){
				$('#select_grid').datagrid('insertRow', {
                    index: 0,
                    row: r
                });
			}
		}
	});
	function handler() {
		switch(this.name) {
			case 'save': toSave();break;
		}
	}
	function removeRow(index){
		 $('#select_grid').datagrid('deleteRow',index);
	 }
	function toSave(){
		var rows = $('#select_grid').datagrid("getRows");
		var userId = [];
		for(var i=0;i < rows.length;i++){
			userId.push(rows[i].id);
		}
		var userIds = userId.join(",");
		$("#input_userIds").val(userIds);
		$.messager.progress({title:'系统提示',text:'数据处理中，请耐心等待...'});
		$.submit('#dataform',function(r) {
			$.messager.progress('close');
			if(r.code<0) return $alert(r.msg);
			top.$prompt('保存成功');
			top.$window.close(window,1,null);
		});
	}
</script>
</head>
<body>
	<div id="toolbar" class="toolbar" ></div>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center',border:false">
			<form id="dataform" action="add" method="post">
				<input type="hidden" name="userIds" id="input_userIds" />
				<table class="form-tbl">
					<tr class="form-tr">
						<th class="form-th">消息标题:</th>
						<td class="form-td">
							<input type="text" name="entity.title" id="add_messageTitle" class="form-text" style="width:170px;" />
						</td>
						<th class="form-th">消息类型:</th>
						
						<td class="form-td">
							<select class="easyui-combobox" name="entity.type" id="comb_type" data-options="required:true,panelHeight:'auto',editable:false ">
								<option value="1">系统消息</option>
								<option value="3">私信 </option>
							</select>
						</td>
					</tr>
					<tr class="form-tr">
						<th class="form-th">消息内容:</th>
						<td class="form-td" colspan="3">
							<input class="easyui-textbox" name="entity.content" id="add_messageContent" style="width:100%;height:60px" data-options="multiline:true">
						</td>
					</tr>
				</table>
			</form>
			<div class="easyui-layout" style="width:100%;height:600px;">
		        <div data-options="region:'east' " title="收信人" style="width:40%">
					<table id="select_grid"></table>
				</div>
		        <div data-options="region:'center',title:'选择收信人'">
		        	<table id="grid"></table>
		        </div>
		    </div>
		</div>
	</div>
</body>
</html>